//
//  TipView.m
//  GuQu
//
//  Created by HELIUM STAR on 15/5/5.
//  Copyright (c) 2015年 HELIUM STAR. All rights reserved.
//

#import "TipView.h"
#define kImageMargin 15

@interface TipView ()

@property (strong, nonatomic) UIView *coverView;

@end

@implementation TipView

//- (instancetype)initWithFrame:(CGRect)frame
//{
//    if (self = [super initWithFrame:frame]) {
//
//    }
//    return self;
//}

- (void)setTipText:(NSString *)tipText
{
    _tipText = tipText;
    [self setUpTipImageAndLabel];
}

- (void)setUpTipImageAndLabel
{
    CGFloat imageWidth = 40;
    CGFloat imageHeight = 40;
    CGFloat labelHeight = 24;
    CGFloat containMargin = 30;
    
    CGFloat containWidth = 150;
    CGFloat containHeight = 100;
    CGFloat containX = kScreenWidth / 2 - containWidth / 2;
    CGFloat containY = containMargin;
    
    UIView *containView = [[UIView alloc] initWithFrame:CGRectMake(containX, containY, containWidth, containHeight)];
    containView.layer.masksToBounds = YES;
    containView.layer.cornerRadius = 5;
    
    UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(containView.width / 2 - imageWidth / 2, kImageMargin, imageWidth, imageHeight)];
    imageView.image = _tipImage;
    
    UILabel *tipLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(imageView.frame) + 10, containView.width, labelHeight)];
    tipLabel.text = _tipText;
    tipLabel.font = [UIFont systemFontOfSize:12];
    tipLabel.textColor = [UIColor whiteColor];
    tipLabel.textAlignment = NSTextAlignmentCenter;
    containView.backgroundColor = [UIColor blackColor];
    containView.alpha = 0.7;
    
    [containView addSubview:imageView];
    [containView addSubview:tipLabel];
    [self addSubview:containView];
    
}

+ (TipView *)showToView:(UIView *)view tipImage:(UIImage *)tipImage tipText:(NSString *)tipText
{
    TipView *tipView = [[self alloc] initWithFrame:CGRectMake(0, 100 * kVRate, kScreenWidth, kScreenHeight - kNavigatationBarHeight)];
    tipView.tipImage = tipImage;
    tipView.tipText = tipText;
    [view addSubview:tipView];
    
    [TipView animateWithDuration:0.5 delay:1.5 options:0 animations:^{
        tipView.alpha = 0;
    } completion:^(BOOL finished) {
        [tipView removeFromSuperview];
    }];
    
    return tipView;
}


@end
